<template>
	<div class="orders-tab">
		<router-view :select="select" :getFullTime="getFullTime" :getDate="getDate" :toast="toast"></router-view>
		<header>
			<ul class="clearFix">
				<li :class="{active:actives['OrderPut']}"> 
					<router-link :to="{name:'OrderPut',query:{orderSelect:'OrderPut',homeSelect:'orders'}}">
						<p>已提交</p>
						<i></i>
					</router-link> 
				</li>
				<li   :class="{active:actives['OrderWait']}"> 
					<router-link :to="{name:'OrderWait',query:{orderSelect:'OrderWait',homeSelect:'orders'}}">
						<p>待服务</p>
						<i></i>
					</router-link> 
				</li>
				<li   :class="{active:actives['OrderProcess']}"> 
					<router-link :to="{name:'OrderProcess',query:{orderSelect:'OrderProcess',homeSelect:'orders'}}">
						<p>服务中</p>
						<i></i>
					</router-link> 
				</li>
				<li   :class="{active:actives['OrderComplete']}"> 
					<router-link :to="{name:'OrderComplete',query:{orderSelect:'OrderComplete',homeSelect:'orders'}}">
						<p>已完成</p>
						<i></i>
					</router-link> 
				</li>
			</ul>
		</header>
	</div>
</template>

<script>
	
	import { mapState } from 'vuex';
	
	export default {
		name: 'orders',
		data() {
			return {
				actives:{"OrderPut":true}
			}
		},
		computed: {
		    ...mapState({
		      token: state => state.user.token,
		    })
		},
		props:['toast','homeSelect'],
		methods: {
			select(key){
				console.log(key);
				let newActives = {};
				Object.keys(this.actives).forEach(item=>{
					newActives[item] = false;
				});
				newActives[key] = true;
				this.actives = {...newActives};
			},
			selectPop(key){
				
			},
	    	getFullTime(timeString=null){
	    		if(!timeString)return "";
	    		const time = new Date(timeString);
	    		return `${time.toLocaleDateString().replace(/\//g,".")} ${time.getHours()} ${time.getMinutes()}`;
	    	},
	    	getDate(timeString=null){
	    		if(!timeString)return "";
	    		const time = new Date(timeString);
	    		return time.toLocaleDateString().replace(/\//g,".");
	    	},
		},
		created(){
			if(this.$route.query.homeSelect){
		  		this.homeSelect(this.$route.query.homeSelect);
			}
//			if(this.$route.query.orderSelect){
//				this.actives[this.$route.query.orderSelect] = true;
//			}else{
//				this.actives['OrderPut'] = true;
//			}
//			this.actives = {...this.actives};
		},
	    beforeRouteEnter(to, from, next){
	    	next(vm=>{
	    		if(vm.token){
	        		next();
	        	}else{
	        		vm.toast("请先登录！");
	        		vm.$router.push({ path: '/login' });
	        	}
	    	})
		},
	}
</script>

<style lang="scss">
.orders-tab{
	padding-top: 60px;
	background: #f5f5f5;
	height: 100%;
	
	header{
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		height: 50px;
		width: 100%;
		background: #ffffff;
		border-bottom: solid 1px #e6e6e6;
		
		ul{
			width: 100%;
			height: 100%;
			padding: 10px 0;
			
			li{
				width: 25%;
				height: 30px;
				position: relative;
				float: left;
				line-height: 28px;
				text-align: center;
				font-size: 1rem;
				a{
					color: #666666;
					font-weight: 400;
				}
				
				i{
					position: absolute;
					left: 50%;
					bottom: 0;
					margin-left: -12px;
					display: none;
					width: 24px;
					height: 2px;
					background: #2dbe60;
				}
				
				&.active{
					a{
						color: #2dbe60;
						font-weight: 500;
					}
					i{
						display: block;
					}
				}
			}
		}
		
	}	
	
	.openMenu{
		position: fixed;
		z-index: 1000;
		top: 0;
		left: 0;
		bottom: 0;
		right: 0;
		background: rgba(0,0,0,0.4);
		animation:openPhoneList .2s ease-in-out;
		
		ul{
			position: fixed;
			width: 100%;
			left: 0;
			right: 0;
			bottom: 0;
			background: #f5f5f5;
			li{
				height: 50px;
				line-height: 50px;
				text-align: center;
				background: #ffffff;
				font-size: 0.85rem;
				color: #979797;
				cursor: pointer;
				&.call{
					font-size: 1.05rem;
					color: #2dbe60;		
					margin-bottom: 5px;
					border-top: solid 1px #e6e6e6;
					a{
						display: block;
						height: 100%;
						width: 100%;
						color: #2dbe60;		
					}
				}
				&.cancle{
					font-size: 1.05rem;
					color: #666666;		
				}
			}
		}
	}
	@keyframes openPhoneList{
	    0%{opacity: 0;}
	    100%{opacity: 1;}
	}
}

.page-orderlist{
	height: auto;
	min-height: 100%;
	background: #f5f5f5;
	
	&.empty{
		background: #f5f5f5 url(../assets/img/bg/emp-list.png) no-repeat center / auto 35px ;
	}
	
	.cont{
		width: 100%;
		padding-bottom: 50px;
		
		.list-item{
			margin-bottom: 10px;
			background: #ffffff;
			padding: 0 10px;
			border-bottom: solid 1px #e6e6e6;
		
			h3{
				height: 45px;
				line-height: 45px;
				width: 100%;
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
				font-size: 1rem;
				border-bottom: solid 1px #e6e6e6;
				
				b{
					font-weight: 600;
					color: #434a4d;
				}
				a{
					color: #4cb0b6;
					display: block;
					padding: 0 15px;
					height: 100%;
					float: right;
					background: transparent url(../assets/img/icon/register-right.png) no-repeat right center / 7px auto;
				}
			}
			
			ul{
				border-bottom: solid 1px #e6e6e6;
				padding: 5px 0;
				font-size: 0.95rem;;
				
				li{
					padding: 4px 0;
					width: 100%;
					position: relative;
					display: table;
					
					label{
					    display: table-cell;
    					vertical-align: top;
    					white-space: nowrap;
    					padding-right: 10px;
    					color: #979797;
					}
					p{
					    display: table-cell;
    					vertical-align: top;
    					text-align: left;
    					width: 100%;
    					line-height: 1.2em;
    					color: #666666;
    					&.em{
    						color: #aa875e;
    					}
					}
				}
			}
			
			.contact{
				height: 45px;
				line-height: 45px;
				width: 100%;
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
				font-size: 0.9rem;
				label{
					color: #979797;
					float: left;
				}
				span{
					color: #2dbe60;
					display: block;
					float: right;
					padding-left: 20px;
					height: 100%;
					cursor: pointer;
					background: transparent url(../assets/img/icon/icon_phone.png) no-repeat left center / 16px auto;
				}
			}
			.appraise{
				height: 45px;
				line-height: 45px;
				width: 100%;
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
				font-size: 0.9rem;
				
				a{
					background: #2dbe60;
					text-align: center;
					padding: 5px 10px;
					border-radius: 15px;
					color: #ffffff;
					display: block;
					line-height: 20px;
					float: right;
					margin-top: 7px;
				}
			}
		}
	}
	
	.order-item{
		margin-bottom: 10px;
		background: #ffffff;
		padding: 0 10px;
		border-top: solid 0.5px #e6e6e6;
		border-bottom: solid 0.5px #e6e6e6;
		
		&>a{
			display: block;
			color: #666666;
		}
	
		h3{
			height: 45px;
			line-height: 45px;
			width: 100%;
			overflow: hidden;
			text-overflow: ellipsis;
			white-space: nowrap;
			font-size: 1rem;
			border-bottom: solid 1px #e6e6e6;
			color: #979797;
			
			b{
				font-weight: 600;
				color: #434a4d;
			}
			p{
				float: left;
				color: #979797;
			}
			a,span{
				color: #4cb0b6;
				display: block;
				padding: 0 15px;
				height: 100%;
				float: right;
				background: transparent url(../assets/img/icon/register-right.png) no-repeat right center / 7px auto;
			}
		}
		
		ul{
			padding: 5px 0;
			font-size: 0.875rem;;
			
			li{
				padding: 0.4em 0;
				width: 100%;
				position: relative;
				display: table;
				
				label{
				    display: table-cell;
					vertical-align: top;
					white-space: nowrap;
					padding-right: 10px;
					color: #979797;
				}
				p{
				    display: table-cell;
					vertical-align: top;
					text-align: left;
					width: 100%;
					line-height: 1.2em;
					color: #666666;
					&.em{
						color: #aa875e;
					}
				}
			}
		}
		
		.contact{
			height: 45px;
			line-height: 45px;
			width: 100%;
			overflow: hidden;
			text-overflow: ellipsis;
			white-space: nowrap;
			font-size: 0.9rem;
			border-top: solid 1px #e6e6e6;
			
			label{
				color: #979797;
				float: left;
			}
			span{
				color: #2dbe60;
				display: block;
				float: right;
				padding-left: 20px;
				height: 100%;
				cursor: pointer;
				background: transparent url(../assets/img/icon/icon_phone.png) no-repeat left center / 16px auto;
			}
		}
		.appraise{
			height: 45px;
			line-height: 45px;
			width: 100%;
			overflow: hidden;
			text-overflow: ellipsis;
			white-space: nowrap;
			font-size: 0.9rem;
			border-top: solid 1px #e6e6e6;
			
			a{
				background: #2dbe60;
				text-align: center;
				padding: 5px 10px;
				border-radius: 15px;
				color: #ffffff;
				display: block;
				line-height: 20px;
				float: right;
				margin-top: 7px;
			}
		}
	}
	
}
</style>
